<template>
  <div>
    <div class="fourData">
      <div>
        <div>
          <div>
            <i class="el-icon-document"></i>
          </div>
        </div>
        <div>
          <p>文章</p>
          <h3>{{ list.articleTotalCount || "暂无数据" }}</h3>
        </div>
      </div>
      <div>
        <div>
          <div>
            <i class="el-icon-folder-opened"></i>
          </div>
        </div>
        <div>
          <p>分类</p>
          <h3>{{ list.categoryTotalCount || "暂无数据" }}</h3>
        </div>
      </div>
      <div>
        <div>
          <div>
            <i class="el-icon-price-tag"></i>
          </div>
        </div>
        <div>
          <p>标签</p>
          <h3>{{ list.tagTotalCount || "暂无数据" }}</h3>
        </div>
      </div>
      <div>
        <div>
          <div>
            <i class="el-icon-view"></i>
          </div>
        </div>
        <div>
          <p>总浏览量</p>
          <h3>{{ list.pvTotalCount || "暂无数据" }}</h3>
        </div>
      </div>
    </div>

    <div class="linelist">
      <div></div>
      <div >
        <h3 style="line-height:20px;text-align:left;padding-left:40px;margin-top:20px">PV 访问量统计</h3>
        <div ref="main"></div>

      </div>
    </div>
  </div>
</template>

<script>
import { index, indexdata } from "../../../../units/htapi";
import * as echarts from "echarts";

export default {
  data() {
    return {
      list: {},
      linelist: {
        pvDates: [],
        pvCounts: [],
      },
    };
  },
  created() {
    this.getIndexData();
  },

  methods: {
    async getIndexData() {
      try {
        let res = await index();
        let res2 = await indexdata();
        this.list = res.data.data;
        // console.log(res, "这个是")
        this.linelist = res2.data.data;
        // console.log(this.linelist, "这个是");
        this.$nextTick(() => {
          this.pvmChart()
        });
      } catch (error) {
        console.log("出错了", error);
      }
    },
    pvmChart() {
      var myChart = echarts.init(this.$refs.main);

     var option = {
        xAxis: {
          type: "category",
          data:this.linelist.pvDates,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: this.linelist.pvCounts,
            type: "line",
          },
        ],
      }
      

      option&&myChart.setOption(option);
    },
  },
};
</script>

<style scoped lang="scss">
* {
  padding: 0;
  margin: 0;
}
.fourData {
  display: flex;
  justify-content: start;
  //   background-color: rgb(255, 203, 203);
  line-height: 40px;
  > div {
    margin: 0 20px;
    width: 200px;
    height: 100px;
    background-color: #fff;
    display: flex;
    justify-content: start;
    align-items: center;
    div:nth-child(1) {
      flex: 1;
      margin-left: 20px;
      div {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background-color: #efefef;
        margin: 0 auto;
        line-height: 40px;
        text-align: center;
      }
    }
    div:nth-child(2) {
      flex: 2;
      text-align: left;
      line-height: 24px;
    }
  }
}
.linelist {
  margin-top: 20px;
  margin-left: 20px;
  width: 1200px;
  height: 400px;
  // background-color: pink;
  display: flex;
  justify-content: space-between;
  div {
    width: 550px;
    height: 100%;
    background-color: rgb(208, 208, 208);
  }
}
</style>